
#include "ntc_lookup.h"


/*!
    \brief      
    \param[in]  none
    \param[out] none
    \retval     none
*/

const float32_t PCB_NTC_Table[2][NTC_TABLE_AMOUNT] =
{
	//  NTC 10K B value 3380
	
    //  K (0~40)
    {
		-0.208480112	,		-0.174678124	,		-0.144996667	,		-0.119608329	,		-0.098451116	,
		-0.081273008	,		-0.067680985	,		-0.057191047	,		-0.049276058	,		-0.043408597	,
		-0.039096608	,		-0.035910302	,		-0.033499479	,		-0.031601237	,		-0.030038677	,
		-0.028711904	,		-0.027583074	,		-0.026657619	,		-0.025963946	,		-0.025533901	,
		-0.025386116	,		-0.025513999	,		-0.025879688	,		-0.026414669	,		-0.027027169	,
		-0.027615771	,		-0.028088103	,		-0.028382917	,		-0.02849348	    ,		-0.028489937	,
		-0.02853821	    ,		-0.028913116	,		-0.030003668	,		-0.032308941	,		-0.036423527	,
		-0.043012266	,		-0.052774724	,		-0.066400669	,		-0.084518548	,		-0.107639628	,
		-0.135300728
        
    },

    // B (0~40)
    {
		161.8562673	,		158.4760685	,		152.539777	,		144.9232758	,		136.4603903	,
		127.8713365	,		119.7161224	,		112.3731661	,		106.041175	,		100.7604597	,
		96.44847125	,		92.94353391	,		90.05054695	,		87.58283199	,		85.39524841	,
		83.40508901	,		81.59896046	,		80.0256865	,		78.77707512	,		77.95999095	,
		77.66441962	,		77.93297408	,		78.73748985	,		79.96794631	,		81.4379466	,
		82.90945276	,		84.13751545	,		84.93351163	,		85.24308924	,		85.23281506	,
		85.37763202	,		86.53984273	,		90.02960876	,		97.63700905	,		111.6266016	,
		134.6871889	,		169.8320374	,		220.248033	,		289.095972	,		379.2681841	,
		489.9125858
    }
};



/*!
    \brief      
    \param[in]  none
    \param[out] none
    \retval     none
*/

const float32_t MOTOR_NTC_Table[2][NTC_TABLE_AMOUNT] =
{
     //  K (0~40)
    {
        -0.953943198    ,  -0.388257392    ,  -0.212859887    ,  -0.146218552    ,  -0.11145717     ,
        -0.090295961    ,  -0.076160514    ,  -0.066114555    ,  -0.058653715    ,  -0.052929784    ,
        -0.048429411    ,  -0.044824519    ,  -0.041896243    ,  -0.039493474    ,  -0.037508988    ,
        -0.035865038    ,  -0.034504347    ,  -0.033384292    ,  -0.032473065    ,  -0.031747102    ,
        -0.031189351    ,  -0.030788138    ,  -0.030536457    ,  -0.030431622    ,  -0.030475225    ,
        -0.03067342     ,  -0.031037586    ,  -0.03158548     ,  -0.032343103    ,  -0.033347662    ,
        -0.034652293    ,  -0.0363338      ,  -0.038505827    ,  -0.041342428    ,  -0.045123027    ,
        -0.050325675    ,  -0.057843155    ,  -0.069568137    ,  -0.090404948    ,  -0.138999087    ,
        -0.352975273
    },

    // B (0~40)
    {
        341.0195575 ,  284.4509769 ,  249.3714759 ,  229.3790753 ,  215.4745228 ,
        204.8939181 ,  196.4126499 ,  189.3804787 ,  183.4118066 ,  178.2602688 ,
        173.7598959 ,  169.794515  ,  166.2805828 ,  163.156984  ,  160.3787032 ,
        157.912778  ,  155.7356721 ,  153.8315784 ,  152.1913703 ,  150.8120401 ,
        149.6965392 ,  148.8539911 ,  148.3002931 ,  148.0591723 ,  148.1638195 ,
        148.6593088 ,  149.6061406 ,  151.0854522 ,  153.2067972 ,  156.1200201 ,
        160.0339127 ,  165.2465825 ,  172.1970705 ,  181.5578532 ,  194.4118883 ,
        212.6211562 ,  239.6840851 ,  283.0665198 ,  362.246402  ,  551.7635439 ,
        1407.668285
    }
};



/*!
    \brief      
    \param[in]  none
    \param[out] none
    \retval     none
*/

float32_t ntcTempLookUp(uint16_t ntc_ad, const float32_t *table)
{
    float32_t  temperature = 0;
    uint16_t   index = 0;

    const float32_t  *p_row = table;
    const float32_t  *p_column = table + NTC_TABLE_AMOUNT;

    index = (uint16_t)((float32_t)ntc_ad * 0.01F);

    if(index > (NTC_TABLE_AMOUNT - 1))
    {
        index = NTC_TABLE_AMOUNT - 1;
    }

    temperature = *(p_row + index) * ntc_ad + *(p_column + index);

    return  temperature;
}

